/**
 * jsp页面的公用js,zhushoulong
 */

//动态改变父类iframe的高度 
//iframe页面调用的js 
function setHeight(height){
	if(height != '1'){
		//height 不为1的时候 设置初始化 子页面的高度
		window.parent.document.getElementById("I1").height=height; 
	}else{
		//取到窗口的高度 
		var winH = $(window).height(); 
		//取到页面的高度 
		var bodyH = $(document).height(); 
		if(bodyH > winH){ 
		window.parent.document.getElementById("I1").height=bodyH; 
		}else{ 
		window.parent.document.getElementById("I1").height=winH; 
		} 
	}
};

//异步上传图片
/**
 * id:所点击的button按钮的id
 * showId 需要展示上传的图片的 span 的Id
 * valueId 上传完成后的路径存放的 隐藏input的id
 * homePath 上传图片的路径的服务路径
 */
var uploadImage = function(id,showId,valueId,homePath){
	var THDialog;
	var uploadFile = $("#"+id);
	new AjaxUpload(uploadFile, {
		action : root
				+ "/control/system/employeeController/uploadFile.do",//提交的远程地址
		name : "imageFile",//上传的文件名
		data : {
			/* "taskId":taskId,
			"colId":colId */
		},
		onSubmit : function(file, ext) {//当提交时
			if (ext && /^(gif|png|jpg)$/.test(ext)) {
				/* THDialog = art.dialog({
					content:'<h3>正在传入</h3>',
					cancel: false,
				    lock: true
				}); */
			} else {
				alert("图片格式不正确");
				return false;
			}
		},
		onComplete : function(file, response) {//提交完成后
			//THDialog.close();
			if(response.length > 0){
				//新异步上传的图片显示的路径
				//var rl = '${imageService}'+response;
				var rl = homePath + response;
				//设置图片路径值
				$('#'+valueId).val(response);
				//展示刚刚上传的图片
				$('#'+showId).html("");
//				var str = "<img src="+rl+" style='width:200px;height:200px;' /><br/>";
				var str = "<img src="+rl+" style='width:200px;height:200px;' />";
				$('#'+showId).append(str);
				//动态改变IFrame的高度
				setHeight('1');
			}else{
				alert("上传失败");
				/* editDialog.close();//关闭维护框
				art.dialog({
					width: 250,
					height: 100,
					fixed: true,
				    padding: 0,
				    title: "提示",
				    content: '<h2>替换成功!</h2>',
				    lock: true,
				    cancel: false,
				    button: [{
					    name: "确定",
					    callback: function () {
					    	window.location.href = root + '/control/task/taskSummativeController/displayEditColumn.do?taskId='+taskId;
					    	//window.location.href = "${root}/control/task/taskDetailColumnController/displayTaskCustom.do?taskId="+taskId;
				        },
				        focus: true
				     }]
				}); */
			}
		}
	});
};


/**
 * 弹出提示信息
 * @param title
 * @param content
 * @param url
 */
function artDalog(title,content,url){
	art.dialog({
		width: 250,
		height: 100,
		fixed: true,
	    padding: 0,
	    title: title,
	    content: content,
	    lock: true,
	    cancel: false,
	    button: [{
		    name: "确定",
		    callback: function () {
		    	if(url != null && url != ''){
		    		window.location.href = url;
		    	}
	        },
	        focus: true
	     }]
	}); 
}